<template>
    <div>
        <van-nav-bar title="订单" left-text="返回" left-arrow @click-left="() => { $router.push('/home/shopping') }" />
        <!-- 地址 -->
        <van-address-list v-model="chosenAddressId" :list="list" :disabled-list="disabledList" default-tag-text="默认"
            :show-add-button="false" />

        <!-- 订单布局 -->
         <van-card
  num="1"
  price="2999.00"
  title="创维彩电40G6A"
  thumb="https://fastly.jsdelivr.net/npm/@vant/assets/ipad.jpeg"
/>

        <!-- <van-card v-for="item in orderinfodata">
            <template #thumb>
                <div style="width: 110px;display: flex;justify-content: space-around;">
                    <van-image width="80" height="80" :src="item.goods.goods_big_logo" />
                </div>
            </template>
            <template #title>
                <div style="font-size: 14px;margin-left: 20px;">{{ item.goods.goods_name }}</div>
            </template>
            <template #price>
                <div style="color: red;margin-left: 15px;">
                    {{ item.goods.goods_price }}
                </div>
            </template>
            <template #num>
                x{{ item.number }}
            </template>
        </van-card> -->
    </div>
    <van-submit-bar :price="paydata.totalPrice * 100" button-text="去支付" @submit="onSubmit" />

</template>

<script setup>
import { ref } from 'vue';
import { getOrderApi, payApi } from '../../request/api'
import { useRoute } from 'vue-router'
const route = new useRoute()
import { useCounterStore } from '../../store/storeCart'
// 可以在组件中的任意位置访问 `store` 变量 ✨
const store = useCounterStore()
//地址
const chosenAddressId = ref('1');
const list = [
    {
        id: '1',
        name: '张三',
        tel: '13000000000',
        address: '浙江省杭州市西湖区文三路 138 号东方通信大厦 7 楼 501 室',
        isDefault: true,
    },
]
//订单支付
const orderinfodata = ref([])
const paydata = ref({
    orderId: '',
    subject: '',
    totalPrice: 0,
})
//获取订单详情
getOrderApi(route.params.id).then(res => {
    let checkeds = store.carts.filter(item => item.checked)
    console.log('获取订单详情', res)
    paydata.value = {
        orderId: res.data.data.orderId,
        subject: res.data.data.product_code,
        totalPrice: res.data.data.totalPrice
    }
    //获取pinia中所有的数据
    let piniadata = store.carts || []
    //获取所有的订单号
    let orderID = checkeds.filter(item => +item.goods_id)
    //通过订单号去pinia中筛选
    piniadata = piniadata.filter(item => {
        return orderID.includes(+item.goods.goods_id)
    })
    orderinfodata.value = piniadata
})
//支付
const onSubmit = () => {
    payApi(paydata.value).then(res => {
        window.open(res.data.data, '_blank')
    })
}
</script>

<style lang="scss" scoped></style>